package com.superman.supermarket.client.view.refundgoods;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.supermarket.client.widget.input.type.ExpressNoInput;
import com.superman.supermarket.client.widget.listbox.MyListBox;

/**
 * 退货页面
 * 
 * @author superman
 * @version 2018年8月21日下午10:51:30
 */
public class RefundGoodsViewImpl extends Composite implements RefundGoodsView {

	interface RefundGoodsViewImplUiBinder extends UiBinder<Widget, RefundGoodsViewImpl> {
	}

	private static RefundGoodsViewImplUiBinder uiBinder = GWT.create(RefundGoodsViewImplUiBinder.class);

	@UiField
	MyListBox companylistbox;
	@UiField
	ExpressNoInput expressnoinput;

	private RefundGoodsViewPresenter presenter;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月21日 下午10:51:27
	 */
	public RefundGoodsViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setExpressCompanyList(List<Map<String, Object>> list) {
		for (Map<String, Object> map : list) {
			companylistbox.addItem(String.valueOf(map.get("COM_NAME")), String.valueOf(map.get("COM_NO")));
		}

		companylistbox.setDefaultText();
	}

	@Override
	public void setPageViewPresenter(IPageViewPresenter presenter) {
		this.presenter = (RefundGoodsViewPresenter) presenter;
	}

	@UiHandler("submitbtn")
	void submit(ClickEvent event) {
		if (expressnoinput.valid()) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("EXPRESS_COMPANY_NO", companylistbox.getValue());
			map.put("EXPRESS_COMPANY", companylistbox.getSelectedItem());
			map.put("EXPRESS_NO", expressnoinput.getValue());
			presenter.submit(map);
		}
	}

}
